﻿using System;
using System.Collections.Generic;
using Citi.RoutineBase;

namespace Citi.PTSConsolidation.SchedulerUI.Bases
{
    public abstract class PreviousYear : IExecutableRoutine
    {
        protected abstract void ExecuteProcess(DateTime referenceDate, ref ICurrentAction currentAction, string networkUser, string networkPassword, Dictionary<string, object> parameters);

        public IEnumerable<RoutineParameter> Parameters
        {
            get
            {
                return new List<RoutineParameter> { 
                    new RoutineParameter{ Description = "Finish Month to generate Previous Year Report", Name ="FinishMonth", Nullable= true, Required = false, Type = typeof(int)}
                };
            }
        }

        public void Rollback(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            
        }

        public void Stop(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {

        }

        public void Start(DateTime scheduledDate, ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            var finishMonth = parameters.ContainsKey("FinishMonth") ? int.Parse(parameters["FinishMonth"].ToString()) : 12;

            if (scheduledDate.Month > finishMonth)
            {
                currentAction.Description = string.Format("This report must be generated until {0}. So this routine will be set as executed but no report will be generated",
                    new DateTime(scheduledDate.Year, finishMonth, 1).ToMonthName());
                return;
            }

            var robotUsername = parameters["RobotUsername"].ToString();
            var robotPassword = parameters["RobotPassword"].ToString();

            ExecuteProcess(scheduledDate, ref currentAction, robotUsername, robotPassword, parameters);
            //ReportGenerationHelper.GenerateClientDailyVarianceReportYear(scheduledDate.Year - 1, scheduledDate, ref currentAction, robotUsername, robotPassword, 4);
        }
    }
}
